from manim import *

class TaylorSeries(Scene):
    def construct(self):
        self.add_sound("happy-114950.mp3")

        # Tex支持中文, 统一Tex Text MathTex字体大小，统一字体颜色
        template = TexTemplate()
        template.add_to_preamble(r"\usepackage{ctex}")
        Tex.set_default(tex_template = template, font_size = 28, color = GRAY_A)
        Text.set_default(font_size = 26, color = GRAY_A)
        MathTex.set_default(font_size = 30, color = GRAY_A)   
        # 统一颜色
        COLOR_ONE = BLUE
        COLOR_COS = GREEN_D
        COLOR_SIN = YELLOW_D
        COLOR_EX = '#F18455'   
        # 统一buff
        DISTANCE = 1

        # 开场
        begin_text = Text("泰勒级数", font_size = 50)
        begin_text_box = RoundedRectangle(stroke_width=4, stroke_color=WHITE, fill_color=BLUE_B, width=4.5, height=2)
        begin_text.move_to(begin_text_box.get_center())
        # begin_text.add_updater(lambda x : x.move_to(begin_text_box.get_center()))
        # begin = VGroup(begin_text, begin_text_box)

        self.play(Write(begin_text))
        self.play(Create(begin_text_box))
        self.play(FadeOut(begin_text, begin_text_box), run_time=2)

        # 描述1: 泰勒级数
        line0 = Text("泰勒级数：")

        taylor_formula = MathTex(
            r"f(x)", r"=", 
            r"f(0)", r"+", 
            r"f^{(1)}(0)", r"\cdot ", r"x", r"+", 
            r"f^{(2)}(0)", r"\cdot ", r"\frac{x^2}{2!}", r"+",
            r"f^{(3)}(0)", r"\cdot ", r"\frac{x^3}{3!}", r"+",
            r"f^{(4)}(0)", r"\cdot ", r"\frac{x^4}{4!}", r"+",
            r"\dots ", r"+",
            r"f^{(n)}(0)", r"\cdot", r"\frac{x^n}{n!}",
        )

        # 将f(0), f'(0)设置为COLOR_ONE
        for i in [2, 4, 8, 12, 16, 22]:
            taylor_formula[i].set_color(COLOR_ONE)

        taylor_series = VGroup(line0, taylor_formula).arrange(RIGHT).shift(UP*2)

        # 提示框
        taylor_series_box = SurroundingRectangle(taylor_series, color=YELLOW)
        taylor_series_box.add_updater(lambda x : x.move_to(taylor_series.get_center()))

        # 播放动画
        self.play(Write(taylor_series))
        self.play(Create(taylor_series_box))

        # 例1: f(x)=e^x
        # f(x), f'(x), f''(x)
        fx = MathTex(
            r"f(x)", r"f^{(1)}(x)", r"f^{(2)}(x)", r"f^{(3)}(x)", r"f^{(4)}(x)", r"\dots ",
            color = COLOR_ONE
        )

        # f(0), f'(0), f''(0)
        f0 = MathTex(
            r"f(0)", r"f^{(1)}(0)", r"f^{(2)}(0)", r"f^{(3)}(0)", r"f^{(4)}(0)", r"\dots ",
            color = COLOR_ONE
        )

        # # 调整fx在泰勒公式正下方
        # temp = 0
        # for i in [2, 4, 8, 12, 16]:
        #     fx[temp].next_to(taylor_formula[i], DOWN*5)
        #     temp = temp + 1
        # fx[-1].next_to(fx[-2], RIGHT*3) # dots在式子最右边

        # # fx第一项在泰勒公式正下方，其它在右边
        # fx[0].next_to(taylor_formula[2], DOWN*5)
        # for i in range(1, len(fx)-1, 1):
        #     fx[i].next_to(fx[i-1], RIGHT * 3)
        # fx[-1].next_to(fx[-2], RIGHT*3) # dots在式子最右边

        # # f0各项与fx各项左对齐
        # for i in range(len(f0)):
        #     f0[i].move_to(fx[i], LEFT)

        # e^x的各项导数
        ex = MathTex(
            r"e^x", r"e^x", r"e^x", r"e^x", r"e^x", r"\dots ",
            color = COLOR_ONE
        )

        # 当x=0时，e^x的各项导数
        e0 = MathTex(
            r"e^0", r"e^0", r"e^0", r"e^0", r"e^0", r"\dots ",
            color = COLOR_ONE
        )

        # 当x=0时，e^x的各项导数结果
        y_e0 = MathTex(
            r"1", r"1", r"1", r"1", r"1", r"\dots ",
            color = COLOR_ONE, font_size = 32
        )

        # # e^x的各项导数在f(x), f'(x)等正下方
        # for i in range(len(ex) - 1):
        #     ex[i].next_to(fx[i], DOWN*2)

        # ex[-1].next_to(fx[-1], DOWN*3) # dots在fx的dots正下方

        # # e0各项与ex各项左对齐
        # for i in range(len(e0)):
        #     e0[i].move_to(ex[i], LEFT)

        # # e0各项结果 与 e0各项 居中对齐
        # for i in range(len(y_e0)):
        #     y_e0[i].move_to(e0[i])

        # 调整 e^x fx f0 e^0 y_e^0 位置
        for i in range(len(fx)):
            fx[i].move_to([i*1.6 - 3, fx[i].get_center()[1],0])
            ex[i].move_to([i*1.6 - 3, ex[i].get_center()[1],0]).shift(DOWN)
            f0[i].move_to([i*1.6 - 3, f0[i].get_center()[1],0])
            e0[i].move_to([i*1.6 - 3, e0[i].get_center()[1],0]).shift(DOWN)
            y_e0[i].move_to([i*1.6 - 3, y_e0[i].get_center()[1], 0]).shift(DOWN)

        # e^x的泰勒级数
        y_ex = MathTex(
            r"e^x", r"=", 
            r"1", r"+", 
            r"1", r"\cdot ", r"x", r"+", 
            r"1", r"\cdot ", r"\frac{x^2}{2!}", r"+",
            r"1", r"\cdot ", r"\frac{x^3}{3!}", r"+",
            r"1", r"\cdot ", r"\frac{x^4}{4!}", r"+",
            r"\dots ", r"+",
            r"1", r"\cdot", r"\frac{x^n}{n!}"
        ).shift(DOWN*2)
        for i in [2, 4, 8, 12, 16, 22]:
            y_ex[i].set_color(COLOR_ONE)

        # 提示文字
        line1_1 = Text("例1:", font_size = 35)
        line1_2 = MathTex(r"f(x) = e^{x}", font_size = 40)
        line1 = VGroup(line1_1, line1_2).arrange(RIGHT).set_color(COLOR_EX)
        line1.next_to(taylor_series_box, DOWN*1.6)

        line2_1 = MathTex(r"e^{x}")
        line2_2 = Text("的各项导数是:")
        line2 = VGroup(line2_1, line2_2).arrange(RIGHT)
        line2.next_to(fx, LEFT*2)

        line3 = Text("当 x=0 时: ").move_to(line2, RIGHT)

        line4 = Text("其具体数值为: ").next_to(y_e0, LEFT*2)

        line5 = Text("故结果为： ").next_to(y_ex, LEFT)


        # 播放动画
        self.play(Write(line1))
        self.play(Write(line2))
        self.play(Write(fx), Write(ex))
        # for i in range(len(fx)):
        #     self.play(Write(fx[i]), Write(ex[i]))

        self.play(ReplacementTransform(line2, line3))
        self.play(ReplacementTransform(fx, f0))
        self.play(ReplacementTransform(ex, e0))
        self.play(Write(line4))
        self.play(ReplacementTransform(e0, y_e0))
        self.play(Write(line5))
        self.play(Write(y_ex), run_time=2)
        self.play(FadeOut(line1, line3, f0, line4, y_e0, line5, y_ex), run_time=2)
        

        # 例2: f(x)=sinx
        # f(x), f'(x), f''(x)
        fx = MathTex(
            r"f(x)", r"f^{(1)}(x)", r"f^{(2)}(x)", r"f^{(3)}(x)", r"f^{(4)}(x)", r"\dots ",
            color = COLOR_ONE
        )

        # f(0), f'(0), f''(0)
        f0 = MathTex(
            r"f(0)", r"f^{(1)}(0)", r"f^{(2)}(0)", r"f^{(3)}(0)", r"f^{(4)}(0)", r"\dots ",
            color = COLOR_ONE
        )

        # sin x的各项导数
        sinx = MathTex(
            r"\sin x", r"\cos x", r"-\sin x", r"-\cos x", r"\sin x", r"\dots ",
            color = COLOR_ONE
        )

        # 当x=0时，sinx的各项导数
        sin0 = MathTex(
            r"\sin 0", r"\cos 0", r"-\sin 0", r"-\cos 0", r"\sin 0", r"\dots ",
            color = COLOR_ONE
        )

        # 当x=0时，sin x的各项导数结果
        y_sin0 = MathTex(
            r"0", r"1", r"0", r"-1", r"0", r"\dots ",
            color = COLOR_ONE, font_size = 32
        )
        # 调整 sinx fx f0 sin0 y_sin0 位置
        for i in range(len(fx)):
            fx[i].move_to([i*1.6 - 3,fx[i].get_center()[1],0])
            sinx[i].move_to([i*1.6 - 3,sinx[i].get_center()[1],0]).shift(DOWN)
            f0[i].move_to([i*1.6 - 3,f0[i].get_center()[1],0])
            sin0[i].move_to([i*1.6 - 3,sin0[i].get_center()[1],0]).shift(DOWN)
            y_sin0[i].move_to([i*1.6 - 3, y_sin0[i].get_center()[1], 0]).shift(DOWN)

        # sinx的泰勒公式
        y_sinx = MathTex(
            r"\sin x", r"=", 
            r"0", r"+", 
            r"1", r"\cdot ", r"x", r"+", 
            r"0", r"\cdot ", r"\frac{x^2}{2!}", r"+",
            r"(-1)", r"\cdot ", r"\frac{x^3}{3!}", r"+",
            r"0", r"\cdot ", r"\frac{x^4}{4!}", r"+",
            r"1", r"\cdot ", r"\frac{x^5}{5!}", r"+", r"\dots"
        ).shift(DOWN*2)
        for i in [2, 4, 8, 12, 16, 20]:
            y_sinx[i].set_color(COLOR_ONE)

        # 去掉0项的sinx的泰勒级数
        y_sinx_result = MathTex(
            r"\sin x", r"=", 
            r"1", r"\cdot ", r"x", r"+", 
            r"(-1)", r"\cdot ", r"\frac{x^3}{3!}", r"+",
            r"1", r"\cdot ", r"\frac{x^5}{5!}", r"+", r"\dots"
        ).move_to(y_sinx, LEFT)

        for i in [2, 6, 10]:
            y_sinx_result[i].set_color(COLOR_ONE)

        # 提示文字
        line1_1 = Text("例2:", font_size = 35)
        line1_2 = MathTex(r"f(x)=\sin x", font_size = 40)
        line1 = VGroup(line1_1, line1_2).arrange(RIGHT).set_color(COLOR_EX)
        line1.next_to(taylor_series_box, DOWN*1.6)

        line2_1 = MathTex(r"\sin x")
        line2_2 = Text("的各项导数是:")
        line2 = VGroup(line2_1, line2_2).arrange(RIGHT)
        line2.next_to(fx, LEFT*1.6)

        line3 = Text("当 x=0 时: ").move_to(line2, RIGHT)

        line4 = Text("其具体数值为: ").next_to(y_sin0, LEFT*3)

        line5 = Text("故结果为： ").next_to(y_sinx, LEFT)

        # 播放动画
        self.play(Write(line1))
        self.play(Write(line2))
        self.play(Write(fx), Write(sinx))

        self.play(ReplacementTransform(line2, line3))
        self.play(ReplacementTransform(fx, f0))
        self.play(ReplacementTransform(sinx, sin0))
        self.play(Write(line4))
        self.play(ReplacementTransform(sin0, y_sin0))     
        self.play(Write(line5))
        self.play(Write(y_sinx), run_time=2)
        self.play(Indicate(y_sinx[2]), Indicate(y_sinx[8]), Indicate(y_sinx[16]), run_time = 1.5)
        self.play(ReplacementTransform(y_sinx, y_sinx_result))
        self.wait()

        self.play(FadeOut(line1, line3, f0, line4, y_sin0, line5, y_sinx_result), run_time=2)

        # 例3: f(x)=cosx
        # f(x), f'(x), f''(x)
        fx = MathTex(
            r"f(x)", r"f^{(1)}(x)", r"f^{(2)}(x)", r"f^{(3)}(x)", r"f^{(4)}(x)", r"\dots ",
            color = COLOR_ONE
        )

        # f(0), f'(0), f''(0)
        f0 = MathTex(
            r"f(0)", r"f^{(1)}(0)", r"f^{(2)}(0)", r"f^{(3)}(0)", r"f^{(4)}(0)", r"\dots ",
            color = COLOR_ONE
        )

        # cos x的各项导数
        cosx = MathTex(
            r"\cos x", r"-\sin x", r"-\cos x", r"\sin x", r"\cos x", r"\dots ",
            color = COLOR_ONE
        )

        # 当x=0时，cosx的各项导数
        cos0 = MathTex(
            r"\cos 0", r"-\sin 0", r"-\cos 0", r"\sin 0", r"\cos 0", r"\dots ",
            color = COLOR_ONE
        )

        # 当x=0时，cos x的各项导数结果
        y_cos0 = MathTex(
            r"1", r"0", r"-1", r"0", r"1", r"\dots ",
            color = COLOR_ONE, font_size = 32
        )

        # 调整 cosx fx f0 cos0 y_cos0 位置
        for i in range(len(fx)):
            fx[i].move_to([i*1.6 - 3,fx[i].get_center()[1],0])
            cosx[i].move_to([i*1.6 - 3,cosx[i].get_center()[1],0]).shift(DOWN)
            f0[i].move_to([i*1.6 - 3,f0[i].get_center()[1],0])
            cos0[i].move_to([i*1.6 - 3,cos0[i].get_center()[1],0]).shift(DOWN)
            y_cos0[i].move_to([i*1.6 - 3, y_cos0[i].get_center()[1], 0]).shift(DOWN)

        # cosx的泰勒公式
        y_cosx = MathTex(
            r"\cos x", r"=", 
            r"1", r"+", 
            r"0", r"\cdot ", r"x", r"+", 
            r"(-1)", r"\cdot ", r"\frac{x^2}{2!}", r"+",
            r"0", r"\cdot ", r"\frac{x^3}{3!}", r"+",
            r"1", r"\cdot ", r"\frac{x^4}{4!}", r"+",
            r"0", r"\cdot ", r"\frac{x^5}{5!}", r"+", r"\dots"
        ).shift(DOWN*2)
        for i in [2, 4, 8, 12, 16, 20]:
            y_cosx[i].set_color(COLOR_ONE)
        
        # 去掉0项的cosx的泰勒级数
        y_cosx_result = MathTex(
            r"\cos x", r"=", 
            r"1", r"+", 
            r"(-1)", r"\cdot ", r"\frac{x^2}{2!}", r"+",
            r"1", r"\cdot ", r"\frac{x^4}{4!}", r"+",
            r"\dots"
        ).move_to(y_cosx, LEFT)

        for i in [2, 4, 8]:
            y_cosx_result[i].set_color(COLOR_ONE)

        # 提示文字
        line1_1 = Text("例3:", font_size = 35)
        line1_2 = MathTex(r"f(x)=\cos x", font_size = 40)
        line1 = VGroup(line1_1, line1_2).arrange(RIGHT).set_color(COLOR_EX) 
        line1.next_to(taylor_series_box, DOWN*1.6)

        line2_1 = MathTex(r"\cos x")
        line2_2 = Text("的各项导数是:")
        line2 = VGroup(line2_1, line2_2).arrange(RIGHT)
        line2.next_to(fx, LEFT*1.6)

        line3 = Text("当 x=0 时: ").move_to(line2, RIGHT)

        line4 = Text("其具体数值为: ").next_to(y_cos0, LEFT*3)

        line5 = Text("故结果为： ").next_to(y_cosx, LEFT)

        # 播放动画
        self.play(Write(line1))
        self.play(Write(line2))
        self.play(Write(fx), Write(cosx))
        # for i in range(len(fx)):
        #     self.play(Write(fx[i]), Write(cosx[i]))

        self.play(ReplacementTransform(line2, line3))
        self.play(ReplacementTransform(fx, f0))
        self.play(ReplacementTransform(cosx, cos0))
        self.play(Write(line4))
        self.play(ReplacementTransform(cos0, y_cos0))
        
        self.play(Write(line5))
        self.play(Write(y_cosx), run_time=2)
        self.play(Indicate(y_cosx[4]), Indicate(y_cosx[12]), Indicate(y_cosx[20]), run_time = 1.5)
        self.play(ReplacementTransform(y_cosx, y_cosx_result))
        self.wait()

        self.play(FadeOut(taylor_series, taylor_series_box,line1, line3, f0, line4, y_cos0, line5, y_cosx_result), run_time=2)













        # 描述2: 欧拉公式推导
        # 开场
        begin_text = Text("欧拉公式", font_size = 50)
        begin_text_box = RoundedRectangle(stroke_width=4, stroke_color=WHITE, fill_color=BLUE_B, width=4.5, height=2)
        begin_text.move_to(begin_text_box.get_center())
        # begin_text.add_updater(lambda x : x.move_to(begin_text_box.get_center()))
        # begin = VGroup(begin_text, begin_text_box)

        self.play(Write(begin_text))
        self.play(Create(begin_text_box))
        self.play(FadeOut(begin_text, begin_text_box), run_time=2)


        # 提示文字
        tex1 = Tex('由例1得, $e^x$的泰勒级数是：',).to_edge(LEFT).shift(UP*2)

        tex2 = Tex('引入虚数', r'$i^2=-1$', '，将', r'$ix$', '代入', r'$x$', '后，').move_to(tex1, LEFT)
        for i in [1, 3, 5]:
            tex2[i].set_color(RED)

        # i^n 提示 及 背景框
        tex3_background = Rectangle(stroke_width=4, stroke_color=GRAY_C, width=2.5, height=3.2).add_background_rectangle(color=GRAY_E)
        i_help = MathTex(
            r"&i^2 = -1 \\ &i^3 = i^2 \cdot i = -i\\ &i^4 = i^3 \cdot i = 1 \\ &i^5 = i^4 \cdot i = i \\ &\dots"
        )
        tex3 = VGroup(Text("提示："), i_help).arrange(DOWN)
        tex3_background.shift(DOWN*1.5 + LEFT*4.5)
        tex3.move_to(tex3_background.get_center())
        tex3.add_updater(lambda x : x.move_to(tex3_background.get_center()))

        tex4 = Tex("由提示得：").next_to(tex2, DOWN, buff=1)
        tex5 = Tex("分离实虚数后，").move_to(tex4, LEFT)
        tex6 = Tex("由例2、例3得：").next_to(tex5, DOWN, buff=1)
        tex7 = Tex("得到欧拉公式：").next_to(tex6, DOWN, buff=1.1)
        tex8 = Tex("用", "$\\theta$", "替换", "$x$", "后得到的欧拉公式是：").next_to(tex6, DOWN, buff=1.1)
        tex8[1].set_color(RED)
        tex8[-2].set_color(RED)

        # y_ex
        y_ex = MathTex(
            r"e^{x}", r"=", 
            r"1", r"+", 
            r"1", r"\cdot ", r"x", r"+", 
            r"1", r"\cdot ", r"\frac{x^2}{2!}", r"+",
            r"1", r"\cdot ", r"\frac{x^3}{3!}", r"+",
            r"1", r"\cdot ", r"\frac{x^4}{4!}", r"+",
            r"\dots ", r"+",
            r"1", r"\cdot", r"\frac{x^n}{n!}"
        ).next_to(tex1, RIGHT, buff=DISTANCE)
        # y_ex 颜色
        for i in [2, 8, 9, 10, 16, 17, 18]:
            y_ex[i].set_color(COLOR_COS)
        for i in [4, 5, 6, 12, 13, 14]:
            y_ex[i].set_color(COLOR_SIN)

        # y_eix_temp
        y_eix_temp = MathTex(
            r"e^{ix}", r"=", 
            r"1", r"+", 
            r"1", r"\cdot ", r"ix", r"+", 
            r"1", r"\cdot ", r"\frac{(ix)^2}{2!}", r"+",
            r"1", r"\cdot ", r"\frac{(ix)^3}{3!}", r"+",
            r"1", r"\cdot ", r"\frac{(ix)^4}{4!}", r"+",
            r"\dots ", r"+",
            r"1", r"\cdot", r"\frac{(ix)^n}{n!}"
        )
        # y_eix_temp 颜色
        for i in [2, 8, 9, 10, 16, 17, 18]:
            y_eix_temp[i].set_color(COLOR_COS)
        for i in [4, 5, 6, 12, 13, 14]:
            y_eix_temp[i].set_color(COLOR_SIN)
        # y_eix_temp 位置
        y_eix_temp.next_to(tex2, RIGHT, buff=0.1)
        # y_eix_temp.add_updater(lambda x : x.next_to(tex2, RIGHT, buff=0.5))

        # y_eix
        y_eix = MathTex(
            r"e^{ix}", r"=", 
            r"1", r"+", 
            r"1", r"\cdot ", r"ix", r"+", 
            r"(-1)", r"\cdot ", r"\frac{x^2}{2!}", r"+",
            r"i", r"\cdot ", r"\frac{x^3}{3!}", r"+",
            r"1", r"\cdot ", r"\frac{x^4}{4!}", r"+",
            r"\dots "
        )
        # y_eix 颜色
        for i in [2, 8, 9, 10, 16, 17, 18]:
            y_eix[i].set_color(COLOR_COS)
        for i in [4, 5, 6, 12, 13, 14]:
            y_eix[i].set_color(COLOR_SIN)
        # y_eix 位置
        y_eix.next_to(tex4, RIGHT, buff=DISTANCE)
        # y_eix.add_updater(lambda x : x.next_to(y_eix_temp, DOWN))


        # 分离实虚数部分后
        real = MathTex(
            r"1", r"-",
            r"\frac{1}{2!}", r"\cdot ", r"x^2", r"+",
            r"\frac{1}{4!}", r"\cdot", r"x^4", r"-",
            r"\dots"
        ).set_color(COLOR_COS)
        imaginary = MathTex(
            r"x", r"-",
            r"\frac{1}{3}", r"\cdot", r"x^3", r"+",
            r"\frac{1}{5}", r"\cdot", r"x^5", r"-",
            r"\dots"
        ).set_color(COLOR_SIN)
        front = MathTex(r"e^x", r"=", r"(")
        middle = MathTex(r")", r"+", r"i", r"(")
        last = MathTex(r")") 
        y_eix_result = VGroup(front, real, middle, imaginary, last).arrange(RIGHT)

        y_eix_result.next_to(tex5, RIGHT, buff=0.2)
        # y_eix_result.add_updater(lambda x : x.move_to(y_eix))

    
        # 去掉0项的cosx的泰勒级数
        y_cosx_result = MathTex(
            r"\cos x", r"=", 
            r"1", r"-", 
            r"\frac{x^2}{2!}", r"+",
            r"\frac{x^4}{4!}", r"+",
            r"\dots"
        ).set_color(COLOR_COS)
        # 去掉0项的sinx的泰勒级数
        y_sinx_result = MathTex(
            r"\sin x", r"=", 
            r"x", r"-", 
            r"\frac{x^3}{3!}", r"+",
            r"\frac{x^5}{5!}", r"+", r"\dots"
        ).set_color(COLOR_SIN)  
        # 组合 位置
        sincos = VGroup(y_cosx_result, y_sinx_result).arrange(RIGHT, buff=1)
        sincos.next_to(tex6, RIGHT, buff=DISTANCE)

        # 用x表示的欧拉公式
        euler_formula = MathTex(r"e^{ix}", r"=", r"\cos x", r"+", r"i", r"\sin x", font_size=50)
        euler_formula[2].set_color(COLOR_COS)
        euler_formula[-1].set_color(COLOR_SIN)
        euler_formula.next_to(tex7, RIGHT, buff=DISTANCE+2)

        # 用角度表示的欧拉公式
        result = MathTex(r"e^{i\theta}", r"=", r"\cos \theta", r"+", r"i", r"\sin \theta", font_size=50)
        result[2].set_color(COLOR_COS)
        result[-1].set_color(COLOR_SIN)
        result.move_to(euler_formula)
        # result.add_updater(lambda x : x.move_to(result.get_center()))

        # 欧拉公式背景框
        result_box = SurroundingRectangle(result, color=YELLOW)
        # euler_formula_box.add_updater(lambda x : x.move_to(euler_formula_box.get_center()))


        # 播放动画
        self.play(Write(tex1))
        self.play(Write(y_ex))
        self.play(Transform(tex1, tex2))
        self.play(ReplacementTransform(y_ex, y_eix_temp), run_time = 2)
        # self.play(Write(y_eix_temp))
        self.wait()

        self.play(Create(tex3_background))
        self.play(Write(tex3))

        self.play(Write(tex4))
        y_eix_temp_copy = y_eix_temp.copy()
        self.play(ReplacementTransform(y_eix_temp_copy, y_eix), run_time = 2)
        # self.play(Write(y_eix))
        self.wait()
        # self.play(ReplacementTransform(y_eix, y_eix_result), run_time = 2)
        self.play(FadeOut(tex3_background), FadeOut(tex3))
        self.play(ReplacementTransform(tex4, tex5))
        self.play(TransformMatchingTex(y_eix, y_eix_result), run_time = 2)
        # self.play(Write(y_eix_result))

        self.play(Write(tex6))
        self.play(Write(sincos))
        self.play(Write(tex7))

        y_eix_result_copy = y_eix_result.copy()
        self.play(ReplacementTransform(y_eix_result_copy ,euler_formula))
        self.play(ReplacementTransform(tex7, tex8))
        self.play(ReplacementTransform(euler_formula, result))
        self.play(Create(result_box))
        self.wait()